﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using TheMovieDB;
using System.IO;
using System.Windows.Forms;

namespace GenerateMovieList
{
    class tmdb
    {
        public tmdb() { }

        public string mdbapi = "2359f2cdfefac3939ede08d472cebef8";

        private string _mdid;
        public string mdid
        {
            get
            {
                return _mdid;
            }
        }
        private string _mdname;
        public string mdname
        {
            get
            {
                return _mdname;
            }
        }
        private string _mdbackdrop;
        public string mdbackdrop
        {
            get
            {
                return _mdbackdrop;
            }
        }
        private string _mdposter;
        public string mdposter
        {
            get
            {
                return _mdposter;
            }
        }
        private string _mdaltname;
        public string mdaltname
        {
            get
            {
                return _mdaltname;
            }
        }
        private string _mdrelease;
        public string mdrelease
        {
            get
            {
                return _mdrelease;
            }
        }
        private string _mdoverview;
        public string mdoverview
        {
            get
            {
                return _mdoverview;
            }
        }
        private string _mdurl;
        public string mdurl
        {
            get
            {
                return _mdurl;
            }
        }
        private string _mdrating;
        public string mdrating
        {
            get
            {
                return _mdrating;
            }
        }
        private string _mdcertification;
        public string mdcertification
        {
            get
            {
                return _mdcertification;
            }
        }
        private string _mdruntime;
        public string mdruntime
        {
            get
            {
                return _mdruntime;
            }
        }
        private string _mdmoviecategory;
        public string mdmoviecategory
        {
            get
            {
                return _mdmoviecategory;
            }
        }
        private string _mdmoviestudio;
        public string mdmoviestudio
        {
            get
            {
                return _mdmoviestudio;
            }
        }
        private string _mdimdbid;
        public string mdimdbid
        {
            get
            {
                return _mdimdbid;
            }
        }
        private string _mdcasts;
        public string mdcasts
        {
            get
            {
                return _mdcasts;
            }
        }
        private string runned = "";
        private List<string> values;
        private void poplist()
        {
            values.Add(_mdid);
            values.Add(_mdname);
            values.Add(_mdbackdrop);
            values.Add(_mdposter);
            values.Add(_mdaltname);
            values.Add(_mdrelease);
            values.Add(_mdoverview);
            values.Add(_mdurl);
            values.Add(_mdrating);
            values.Add(_mdcertification);
            values.Add(_mdruntime);
            values.Add(_mdmoviecategory);
            values.Add(_mdmoviestudio);
            values.Add(_mdimdbid);
            values.Add(_mdcasts);
        }

        public void themoviedb(string filename, string path)
        {
            _mdid = "";
            _mdname = "";
            _mdbackdrop = "";
            _mdposter = "";
            _mdaltname = "";
            _mdrelease = "";
            _mdoverview = "";
            _mdurl = "";
            _mdrating = "";
            _mdcertification = "";
            _mdruntime = "";
            _mdmoviecategory = "";
            _mdmoviestudio = "";
            _mdimdbid = "";
            _mdcasts = "";
            TmdbAPI api = new TmdbAPI(mdbapi);
            TmdbMovie[] movies = api.MovieSearch(filename);
            foreach (TmdbMovie movie in movies)
            {
                string ID = movie.Id.ToString();
                string name = movie.Name;
                string alname = movie.AlternativeName;
                string release = movie.ReleasedString;
                string overview = movie.Overview;
                string url = movie.Url;
                var movieq = MessageBox.Show("Filename: " + filename + "\rIs this the movie?" + "\rName: " + name + "\rAlternative Name: " + alname + "\rReleased: " + release + "\rOverview: " + overview, "Filename: " + filename, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (movieq == DialogResult.Yes)
                {
                    _mdbackdrop = "";
                    _mdposter = "";
                    foreach (TmdbImage image in movie.Images)
                    {
                        if (image.Type == TmdbImageType.backdrop)
                        {
                            if (image.Size == TmdbImageSize.original)
                            {
                                string imageurl = image.Url.Replace("org//", "org/");
                                _mdbackdrop = imageurl;
                            }
                        }
                        if (image.Type == TmdbImageType.poster)
                        {
                            if (image.Size == TmdbImageSize.original)
                            {
                                string imageurl = image.Url.Replace("org//", "org/");
                                _mdposter = imageurl;
                            }
                        }
                    }
                    _mdid = ID;
                    TmdbMovie info = api.GetMovieInfo(int.Parse(ID));
                    if (info.Id.ToString() == ID.ToString())
                    {
                        _mdname = info.Name;
                        _mdaltname = info.AlternativeName;
                        _mdrelease = info.ReleasedString;
                        _mdoverview = info.Overview;
                        _mdurl = info.Url;
                        _mdrating = info.Rating.ToString();
                        _mdcertification = info.Certification;
                        _mdruntime = info.Runtime;
                        _mdimdbid = info.ImdbId;
                        string casts = "";
                        foreach (TmdbCastPerson person in info.Cast)
                        {
                            casts += person.Name + "|";
                        }
                        if (casts == "|" || casts == string.Empty)
                        {
                            casts = "Empty";
                        }
                        else
                        {
                            _mdcasts += casts.Substring(0, casts.Length - 1);
                        }
                        string categories = "";
                        foreach (TmdbCategory category in info.Categories)
                        {
                            categories += category.Name + "|";
                        }
                        if (categories == "|" || categories == string.Empty)
                        {
                            categories = "Empty";
                        }
                        else
                        {
                            _mdmoviecategory += categories.Substring(0, categories.Length - 1);
                        }
                        string studios = "";
                        foreach (TmdbStudio studio in info.Studios)
                        {
                            studios += studio.Name + "|";
                        }
                        if (studios == "|" || studios == string.Empty)
                        {
                            studios = "Empty";
                        }
                        else
                        {
                            _mdmoviestudio += studios.Substring(0, studios.Length - 1);
                        }
                    }
                    break;
                }
            }
        }
        public void themoviedbmissing(string filename, string path, string idnr, string moviename)
        {
            _mdid = "";
            _mdname = "";
            _mdbackdrop = "";
            _mdposter = "";
            _mdaltname = "";
            _mdrelease = "";
            _mdoverview = "";
            _mdurl = "";
            _mdrating = "";
            _mdcertification = "";
            _mdruntime = "";
            _mdmoviecategory = "";
            _mdmoviestudio = "";
            _mdimdbid = "";
            _mdcasts = "";
            TmdbAPI api = new TmdbAPI(mdbapi);
            TmdbMovie[] movies = api.MovieSearch(filename);
            foreach (TmdbMovie movie in movies)
            {
                if (idnr == movie.Id.ToString() && moviename == movie.Name)
                {
                    foreach (TmdbImage image in movie.Images)
                    {
                        if (image.Type == TmdbImageType.backdrop)
                        {
                            if (image.Size == TmdbImageSize.original)
                            {
                                string imageurl = image.Url.Replace("org//", "org/");
                                _mdbackdrop = imageurl;
                            }
                        }
                        if (image.Type == TmdbImageType.poster)
                        {
                            if (image.Size == TmdbImageSize.original)
                            {
                                string imageurl = image.Url.Replace("org//", "org/");
                                _mdposter = imageurl;
                            }
                        }
                    }
                    _mdid = idnr;
                    TmdbMovie info = api.GetMovieInfo(int.Parse(idnr));
                    if (info.Id.ToString() == idnr.ToString())
                    {
                        _mdname = info.Name;
                        _mdaltname = info.AlternativeName;
                        _mdrelease = info.ReleasedString;
                        _mdoverview = info.Overview;
                        _mdurl = info.Url;
                        _mdrating = info.Rating.ToString();
                        _mdcertification = info.Certification;
                        _mdruntime = info.Runtime;
                        _mdimdbid = info.ImdbId;
                        string casts = "";
                        foreach (TmdbCastPerson person in info.Cast)
                        {
                            casts += person.Name + "|";
                        }
                        if (casts == "|" || casts == string.Empty)
                        {
                            casts = "Empty";
                        }
                        else
                        {
                            _mdcasts += casts.Substring(0, casts.Length - 1);
                        }
                        string categories = "";
                        foreach (TmdbCategory category in info.Categories)
                        {
                            categories += category.Name + "|";
                        }
                        if (categories == "|" || categories == string.Empty)
                        {
                            categories = "Empty";
                        }
                        else
                        {
                            _mdmoviecategory += categories.Substring(0, categories.Length - 1);
                        }
                        string studios = "";
                        foreach (TmdbStudio studio in info.Studios)
                        {
                            studios += studio.Name + "|";
                        }
                        if (studios == "|" || studios == string.Empty)
                        {
                            studios = "Empty";
                        }
                        else
                        {
                            _mdmoviestudio += studios.Substring(0, studios.Length - 1);
                        }
                    }
                    break;
                }
            }
        }
        public void themoviedbid(string filename, string path, string ID)
        {
            _mdid = "";
            _mdname = "";
            _mdbackdrop = "";
            _mdposter = "";
            _mdaltname = "";
            _mdrelease = "";
            _mdoverview = "";
            _mdurl = "";
            _mdrating = "";
            _mdcertification = "";
            _mdruntime = "";
            _mdmoviecategory = "";
            _mdmoviestudio = "";
            _mdimdbid = "";
            _mdcasts = "";
            TmdbAPI api = new TmdbAPI(mdbapi);
            TmdbMovie info = api.GetMovieInfo(int.Parse(ID));
            if (info.Id.ToString() == ID.ToString())
            {
                _mdname = info.Name;
                _mdaltname = info.AlternativeName;
                _mdrelease = info.ReleasedString;
                _mdoverview = info.Overview;
                _mdurl = info.Url;
                _mdrating = info.Rating.ToString();
                _mdcertification = info.Certification;
                _mdruntime = info.Runtime;
                _mdimdbid = info.ImdbId;
                string casts = "";
                foreach (TmdbCastPerson person in info.Cast)
                {
                    casts += person.Name + "|";
                }
                if (casts == "|" || casts == string.Empty)
                {
                    casts = "Empty";
                }
                else
                {
                    _mdcasts += casts.Substring(0, casts.Length - 1);
                }
                string categories = "";
                foreach (TmdbCategory category in info.Categories)
                {
                    categories += category.Name + "|";
                }
                if (categories == "|" || categories == string.Empty)
                {
                    categories = "Empty";
                }
                else
                {
                    _mdmoviecategory += categories.Substring(0, categories.Length - 1);
                }
                string studios = "";
                foreach (TmdbStudio studio in info.Studios)
                {
                    studios += studio.Name + "|";
                }
                if (studios == "|" || studios == string.Empty)
                {
                    studios = "Empty";
                }
                else
                {
                    _mdmoviestudio += studios.Substring(0, studios.Length - 1);
                }

            }
        }
        public void uselocalxml(string localxmlfile)
        {
            _mdid = "";
            _mdname = "";
            _mdbackdrop = "";
            _mdposter = "";
            _mdaltname = "";
            _mdrelease = "";
            _mdoverview = "";
            _mdurl = "";
            _mdrating = "";
            _mdcertification = "";
            _mdruntime = "";
            _mdmoviecategory = "";
            _mdmoviestudio = "";
            _mdimdbid = "";
            _mdcasts = "";
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(localxmlfile);
            XmlNodeList elements = xmldoc.SelectNodes("Movie/Details");
            foreach (XmlNode element in elements)
            {
                try
                {
                    _mdid = element.SelectSingleNode("ID").InnerText;
                    _mdname = element.SelectSingleNode("Name").InnerText;
                    _mdbackdrop = element.SelectSingleNode("BackdropUrl").InnerText;
                    _mdposter = element.SelectSingleNode("PosterUrl").InnerText;
                    _mdaltname = element.SelectSingleNode("AlternativeName").InnerText;
                    _mdrelease = element.SelectSingleNode("Released").InnerText;
                    _mdoverview = element.SelectSingleNode("Overview").InnerText;
                    _mdurl = element.SelectSingleNode("Url").InnerText;
                    _mdrating = element.SelectSingleNode("Rating").InnerText;
                    _mdcertification = element.SelectSingleNode("Certification").InnerText;
                    _mdruntime = element.SelectSingleNode("Runtime").InnerText;
                    _mdmoviecategory = element.SelectSingleNode("Categories").InnerText;
                    _mdmoviestudio = element.SelectSingleNode("MovieStudios").InnerText;
                    _mdimdbid = element.SelectSingleNode("IMDBID").InnerText;
                    _mdcasts = element.SelectSingleNode("Cast").InnerText;
                    poplist();
                }
                catch (Exception e)
                {
                    //Do Nothing
                }
            }
            foreach (string value in values)
            {
                if (value == string.Empty)
                {

                }
            }
            runned += _mdname + " ";
        }
        public void generatexmlmovies(string outputfile, string filename, string extension, string directorypaths, string roottext, string topnametext)
        {
            string xmlid = "";
            string xmlname = "";
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(outputfile);
                XmlNodeList elements = xmldoc.SelectNodes("Movies/Movie");          
                foreach (XmlNode element in elements)
                {
                    try
                    {
                        xmlid += element.SelectSingleNode("ID").InnerText;
                        xmlname += element.SelectSingleNode("Name").InnerText;
                    }
                    catch { }
                }
            }
            catch { }
            if (xmlid.Contains(mdid) == false && xmlname.Contains(mdname) == false)
            {
                //pick whatever filename with .xml extension
                XmlDocument xmlDoc = new XmlDocument();

                try
                {
                    xmlDoc.Load(outputfile);
                }
                catch (System.IO.FileNotFoundException)
                {
                    //if file is not found, create a new xml file
                    XmlTextWriter xmlWriter = new XmlTextWriter(outputfile, System.Text.Encoding.UTF8);
                    xmlWriter.Formatting = Formatting.Indented;
                    xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                    xmlWriter.WriteStartElement(roottext);
                    //If WriteProcessingInstruction is used as above,
                    //Do not use WriteEndElement() here
                    //xmlWriter.WriteEndElement();
                    //it will cause the &ltRoot></Root> to be &ltRoot />
                    xmlWriter.Close();
                    xmlDoc.Load(outputfile);
                }

                XmlNode root = xmlDoc.DocumentElement;
                XmlElement childNode = xmlDoc.CreateElement(topnametext);
                root.AppendChild(childNode);
                XmlElement id = xmlDoc.CreateElement("ID");
                XmlText idnr = xmlDoc.CreateTextNode(mdid);
                XmlElement movie = xmlDoc.CreateElement("Filename");
                XmlText moviename = xmlDoc.CreateTextNode(filename);
                XmlElement extensions = xmlDoc.CreateElement("Extension");
                XmlText extensionstype = xmlDoc.CreateTextNode(extension);
                XmlElement directoryname = xmlDoc.CreateElement("Directory");
                XmlText directorypath = xmlDoc.CreateTextNode(directorypaths);
                XmlElement mdbnames = xmlDoc.CreateElement("Name");
                XmlText mdbnamestext = xmlDoc.CreateTextNode(mdname);
                XmlElement mdbaltnames = xmlDoc.CreateElement("AlternativeName");
                XmlText mdbaltnamestext = xmlDoc.CreateTextNode(mdaltname);
                XmlElement mdbreleases = xmlDoc.CreateElement("Released");
                XmlText mdbreleasestext = xmlDoc.CreateTextNode(mdrelease);
                XmlElement mdboverviews = xmlDoc.CreateElement("Overview");
                XmlText mdboverviewstext = xmlDoc.CreateTextNode(mdoverview);
                XmlElement mdburls = xmlDoc.CreateElement("Url");
                XmlText mdburltext = xmlDoc.CreateTextNode(mdurl);
                XmlElement mdbratings = xmlDoc.CreateElement("Rating");
                XmlText mdbratingtext = xmlDoc.CreateTextNode(mdrating);
                XmlElement mdbruntimes = xmlDoc.CreateElement("Runtime");
                XmlText mdbruntimetext = xmlDoc.CreateTextNode(mdruntime);
                XmlElement mdbcerti = xmlDoc.CreateElement("Certification");
                XmlText mdbcertitext = xmlDoc.CreateTextNode(mdcertification);
                XmlElement mdbstudio = xmlDoc.CreateElement("MovieStudios");
                XmlText mdbstudiotext = xmlDoc.CreateTextNode(mdmoviestudio);
                XmlElement mdbcategory = xmlDoc.CreateElement("Categories");
                XmlText mdbcategorytext = xmlDoc.CreateTextNode(mdmoviecategory);
                XmlElement mdbbackd = xmlDoc.CreateElement("BackdropUrl");
                XmlText mdbbackdtext = xmlDoc.CreateTextNode(mdbackdrop);
                XmlElement mdbpost = xmlDoc.CreateElement("PosterUrl");
                XmlText mdbposttext = xmlDoc.CreateTextNode(mdposter);
                XmlElement mdbimdb = xmlDoc.CreateElement("IMDBID");
                XmlText mdbimdbnr = xmlDoc.CreateTextNode(mdimdbid);
                XmlElement mdbcast = xmlDoc.CreateElement("Cast");
                XmlText mdbcastpersons = xmlDoc.CreateTextNode(mdcasts);

                childNode.AppendChild(id);
                id.AppendChild(idnr);
                childNode.AppendChild(movie);
                movie.AppendChild(moviename);
                childNode.AppendChild(extensions);
                extensions.AppendChild(extensionstype);
                childNode.AppendChild(directoryname);
                directoryname.AppendChild(directorypath);
                childNode.AppendChild(mdbnames);
                mdbnames.AppendChild(mdbnamestext);
                childNode.AppendChild(mdbaltnames);
                mdbaltnames.AppendChild(mdbaltnamestext);
                childNode.AppendChild(mdbreleases);
                mdbreleases.AppendChild(mdbreleasestext);
                childNode.AppendChild(mdboverviews);
                mdboverviews.AppendChild(mdboverviewstext);
                childNode.AppendChild(mdburls);
                mdburls.AppendChild(mdburltext);
                childNode.AppendChild(mdbratings);
                mdbratings.AppendChild(mdbratingtext);
                childNode.AppendChild(mdbruntimes);
                mdbruntimes.AppendChild(mdbruntimetext);
                childNode.AppendChild(mdbcerti);
                mdbcerti.AppendChild(mdbcertitext);
                childNode.AppendChild(mdbstudio);
                mdbstudio.AppendChild(mdbstudiotext);
                childNode.AppendChild(mdbcategory);
                mdbcategory.AppendChild(mdbcategorytext);
                childNode.AppendChild(mdbbackd);
                mdbbackd.AppendChild(mdbbackdtext);
                childNode.AppendChild(mdbpost);
                mdbpost.AppendChild(mdbposttext);
                childNode.AppendChild(mdbimdb);
                mdbimdb.AppendChild(mdbimdbnr);
                childNode.AppendChild(mdbcast);
                mdbcast.AppendChild(mdbcastpersons);
                xmlDoc.Save(outputfile);
            }
        }
        public void generatexmldetails(string outputfile, string filename, string extension, string directorypaths, string roottext, string topnametext)
        {
            if (File.Exists(outputfile))
                File.Delete(outputfile);
            XmlDocument xmlDoc = new XmlDocument();
            //if file is not found, create a new xml file
            XmlTextWriter xmlWriter = new XmlTextWriter(outputfile, System.Text.Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement(roottext);
            //If WriteProcessingInstruction is used as above,
            //Do not use WriteEndElement() here
            //xmlWriter.WriteEndElement();
            //it will cause the &ltRoot></Root> to be &ltRoot />
            xmlWriter.Close();
            xmlDoc.Load(outputfile);

            XmlNode root = xmlDoc.DocumentElement;
            XmlElement childNode = xmlDoc.CreateElement(topnametext);
            root.AppendChild(childNode);
            XmlElement id = xmlDoc.CreateElement("ID");
            XmlText idnr = xmlDoc.CreateTextNode(mdid);
            XmlElement movie = xmlDoc.CreateElement("Filename");
            XmlText moviename = xmlDoc.CreateTextNode(filename);
            XmlElement extensions = xmlDoc.CreateElement("Extension");
            XmlText extensionstype = xmlDoc.CreateTextNode(extension);
            XmlElement directoryname = xmlDoc.CreateElement("Directory");
            XmlText directorypath = xmlDoc.CreateTextNode(directorypaths);
            XmlElement mdbnames = xmlDoc.CreateElement("Name");
            XmlText mdbnamestext = xmlDoc.CreateTextNode(mdname);
            XmlElement mdbaltnames = xmlDoc.CreateElement("AlternativeName");
            XmlText mdbaltnamestext = xmlDoc.CreateTextNode(mdaltname);
            XmlElement mdbreleases = xmlDoc.CreateElement("Released");
            XmlText mdbreleasestext = xmlDoc.CreateTextNode(mdrelease);
            XmlElement mdboverviews = xmlDoc.CreateElement("Overview");
            XmlText mdboverviewstext = xmlDoc.CreateTextNode(mdoverview);
            XmlElement mdburls = xmlDoc.CreateElement("Url");
            XmlText mdburltext = xmlDoc.CreateTextNode(mdurl);
            XmlElement mdbratings = xmlDoc.CreateElement("Rating");
            XmlText mdbratingtext = xmlDoc.CreateTextNode(mdrating);
            XmlElement mdbruntimes = xmlDoc.CreateElement("Runtime");
            XmlText mdbruntimetext = xmlDoc.CreateTextNode(mdruntime);
            XmlElement mdbcerti = xmlDoc.CreateElement("Certification");
            XmlText mdbcertitext = xmlDoc.CreateTextNode(mdcertification);
            XmlElement mdbstudio = xmlDoc.CreateElement("MovieStudios");
            XmlText mdbstudiotext = xmlDoc.CreateTextNode(mdmoviestudio);
            XmlElement mdbcategory = xmlDoc.CreateElement("Categories");
            XmlText mdbcategorytext = xmlDoc.CreateTextNode(mdmoviecategory);
            XmlElement mdbbackd = xmlDoc.CreateElement("BackdropUrl");
            XmlText mdbbackdtext = xmlDoc.CreateTextNode(mdbackdrop);
            XmlElement mdbpost = xmlDoc.CreateElement("PosterUrl");
            XmlText mdbposttext = xmlDoc.CreateTextNode(mdposter);
            XmlElement mdbimdb = xmlDoc.CreateElement("IMDBID");
            XmlText mdbimdbnr = xmlDoc.CreateTextNode(mdimdbid);
            XmlElement mdbcast = xmlDoc.CreateElement("Cast");
            XmlText mdbcastpersons = xmlDoc.CreateTextNode(mdcasts);

            childNode.AppendChild(id);
            id.AppendChild(idnr);
            childNode.AppendChild(movie);
            movie.AppendChild(moviename);
            childNode.AppendChild(extensions);
            extensions.AppendChild(extensionstype);
            childNode.AppendChild(directoryname);
            directoryname.AppendChild(directorypath);
            childNode.AppendChild(mdbnames);
            mdbnames.AppendChild(mdbnamestext);
            childNode.AppendChild(mdbaltnames);
            mdbaltnames.AppendChild(mdbaltnamestext);
            childNode.AppendChild(mdbreleases);
            mdbreleases.AppendChild(mdbreleasestext);
            childNode.AppendChild(mdboverviews);
            mdboverviews.AppendChild(mdboverviewstext);
            childNode.AppendChild(mdburls);
            mdburls.AppendChild(mdburltext);
            childNode.AppendChild(mdbratings);
            mdbratings.AppendChild(mdbratingtext);
            childNode.AppendChild(mdbruntimes);
            mdbruntimes.AppendChild(mdbruntimetext);
            childNode.AppendChild(mdbcerti);
            mdbcerti.AppendChild(mdbcertitext);
            childNode.AppendChild(mdbstudio);
            mdbstudio.AppendChild(mdbstudiotext);
            childNode.AppendChild(mdbcategory);
            mdbcategory.AppendChild(mdbcategorytext);
            childNode.AppendChild(mdbbackd);
            mdbbackd.AppendChild(mdbbackdtext);
            childNode.AppendChild(mdbpost);
            mdbpost.AppendChild(mdbposttext);
            childNode.AppendChild(mdbimdb);
            mdbimdb.AppendChild(mdbimdbnr);
            childNode.AppendChild(mdbcast);
            mdbcast.AppendChild(mdbcastpersons);
            xmlDoc.Save(outputfile);
        }
        public void localnfofile(string path)
        {
            string mptxtfile = path + @"\info.nfo";
            if (File.Exists(mptxtfile))
            {
                File.Delete(mptxtfile);
                localnfofile(path);
            }
            else
            {
                TextWriter tw = new StreamWriter(mptxtfile);
                tw.WriteLine("Title: " + mdname);
                tw.WriteLine("SortBy Title: " + mdname);
                tw.WriteLine("IMDB ID: " + mdimdbid);
                tw.WriteLine("IMDB Address: " + "http://www.imdb.com/title/" + mdimdbid);
                tw.WriteLine("Year: " + mdrelease);
                tw.WriteLine("Genres: |" + mdmoviecategory + "|");
                tw.WriteLine("Certification: " + mdcertification);
                tw.WriteLine("Summary: " + mdoverview);
                tw.WriteLine("Actors: " + mdcasts);
                tw.WriteLine("Runtime: " + mdruntime);
                tw.Close();
            }
        }
        public void shortcutimdb(string path)
        {
            string shortcut = path + @"\" + mdname + ".url";
            if (File.Exists(shortcut))
            {
                File.Delete(shortcut);
                shortcutimdb(path);
            }
            else
            {
                TextWriter url = new StreamWriter(shortcut);
                url.WriteLine("[InternetShortcut]");
                url.WriteLine("URL=" + "http://www.imdb.com/title/" + mdimdbid);
                url.Close();
            }
        }
    }
}
